package neuralmusic.brain.gui;

import java.util.Collection;
import java.util.HashMap;
import neuralmusic.brain.module.FireObserver;
import neuralmusic.brain.module.Neuron;

public class FireRecorder implements FireObserver {

	
	HashMap<Neuron,FireRecord> records=new HashMap<Neuron,FireRecord>();
	private double endTime=0;
	
	public int size() {
		return records.size();
	}

	public double startTime() {
		return 0;
	}

	public double endTime() {
		return endTime;
	}
	
	Collection <FireRecord> getRecords() {
		return records.values();
	}

	public void addNeuron(Neuron n,String label) {
		assert(n.fireObserver == null);
		n.fireObserver = this;
		records.put(n,new FireRecord(label));
	}

	@Override
	public void notify(Neuron neuron) {
		FireRecord rec=records.get(neuron);
		
		double t=neuron.getWhen();
		rec.add(new FireEvent(t));
		assert(t >=endTime);
		endTime=t;
	}

	public FireRecord getEvents(Neuron neuron) {
		return records.get(neuron);		
	}

}
